#!/usr/bin/python

""" createAdminCodeFile.py
    Creates files and generates pre-formatted headers for TCDB
    code files. Takes any number of filenames as command line params

    This script is identical to createCodeFile.py in every way, except
    for the line requiring 'require_admin.php' in the script; this 
    ensures that we're creating files only Admins can see
    
    For info on headers, see http://www.gnu.org/copyleft/gpl-howto.html """

__author__ = "Dylan J. Sather"
__created__ = "2009-06-03"
__lastEdited__ = "2009-06-15"

import sys
from time import strftime

# For each file in sys.argv...

for file in sys.argv[1:]:

    # Create file, lines

    filename = file
    lines = ["<?php \n", 
    "/* \n", 
    " * This file is part of TCDB. \n", 
    " * \n",
    " * Copyright (C) 2000-2009 \n",
    " * Technology Consultant Corps \n",
    " * Grinnell College \n",
    " * Grinnell, IA, 50112 \n",
    " * tc@grinnell.edu \n",
    " * \n", 
    " * TCDB is free software; you can redistribute it and/or modify \n",
    " * it under the terms of the GNU General Public License as published by \n",
    " * the Free Software Foundation; either version 3 of the License, or \n",
    " * (at your option) any later version. \n",
    " * \n",
    " * TCDB is distributed in the hope that it will be useful, \n",
    " * but WITHOUT ANY WARRANTY; without even the implied warranty of \n", 
    " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n",
    " * GNU General Public License for more details. \n",
    " * \n",
    " * You should have received a copy of the GNU General Public License \n",
    " * along with TCDB. If not, see <http://www.gnu.org/licenses/>. \n",
    " * \n",
    " \n",
    " ============================================================================= \n",
    " \n",
    " * " + filename + " -- [Insert summary here] \n",
    " * \n",
    " * Author: \n",
    " * Created: " + strftime("%Y-%m-%d") + " \n",
    " * Last edited: " + strftime("%Y-%m-%d") + " \n",
    " */ \n",
    " \n",
    "$page_title = \"" + filename + "\"; \n",
    "\n",
    "require('init.php'); \n",
    "require('require_login.php'); \n",
    "require('require_admin.php'); \n",
    "include('header.php'); \n",
    "\n",
    "include('footer.php'); \n",
    "\n",
    "?> \n"]

    # Open file, writelines, close file
    FILE = open(filename, "w")
    FILE.writelines(lines)
    FILE.close()
